package net.xdclass.component;

import net.xdclass.enums.ProductOrderPayTypeEnum;
import net.xdclass.vo.PayInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author NJUPT wly
 * @Date 2021/9/29 12:41 下午
 * @Version 1.0
 */
@Component
public class PayFactory {

    @Autowired
    private AliPayStrategy aliPayStrategy;

    @Autowired
    private WechatStrategy wechatStrategy;

    /**
     * 创建支付
     * @param payInfoVo
     * @return
     */
    public String pay(PayInfoVo payInfoVo){

        String payType = payInfoVo.getPayType();

        if (ProductOrderPayTypeEnum.ALIPAY.name().equalsIgnoreCase(payType)){

            PayStrategyContext payStrategyContext = new PayStrategyContext(aliPayStrategy);

            return payStrategyContext.executeUnifiedOrder(payInfoVo);
        } else if (ProductOrderPayTypeEnum.WECHAT.name().equalsIgnoreCase(payType)){
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatStrategy);

            return payStrategyContext.executeUnifiedOrder(payInfoVo);
        }
        return "";
    }

    /**
     * 查询订单状态
     * @param payInfoVo
     * @return
     */
    public String queryPaySuccess(PayInfoVo payInfoVo){
        String payType = payInfoVo.getPayType();

        if (ProductOrderPayTypeEnum.ALIPAY.name().equalsIgnoreCase(payType)){

            PayStrategyContext payStrategyContext = new PayStrategyContext(aliPayStrategy);

            return payStrategyContext.executeQueryPaySuccess(payInfoVo);
        } else if (ProductOrderPayTypeEnum.WECHAT.name().equalsIgnoreCase(payType)){
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatStrategy);

            return payStrategyContext.executeQueryPaySuccess(payInfoVo);
        }
        return "";
    }
}
